#include "server.h"
#include <QtDebug>

Server::Server()
{
    tcpserver = new QTcpServer(this);
    tcpsocket = new QTcpSocket(this);

    QObject::connect(tcpserver,&QTcpServer::newConnection,
                     this,&Server::onConnection);
}

Server::~Server()
{
    delete tcpserver;
    delete tcpsocket;
}

void Server::tcpstart()
{
    //网络模块:IP地址,端口,监听
    QString IP = "192.168.31.206";
    quint16 port = 8080;
    QHostAddress addr(IP);
    tcpserver->listen(addr,port);
}

void Server::onConnection()
{
    tcpsocket = tcpserver->nextPendingConnection();
    qDebug()<<"peer address:"+tcpsocket->peerAddress().toString();
}
